<!DOCTYPE html>
<html class="x-admin-sm">
<head>
  <meta charset="UTF-8">
  <title>profile</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
  <link rel="stylesheet" href="{*cdn*}css/font.css">
  <link rel="stylesheet" href="{*cdn*}css/xadmin.css">
  <script type="text/javascript" src="{*cdn*}lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="{*cdn*}js/xadmin.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">{*locale['dashboard.header.profile.update_userinfo']*}</div>
      <div class="layui-card-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.name']*}
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="name" value="{*user.name*}" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.name.notice']*}
              </div>
          </div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.username']*}
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="username" value="{*user.username*}" lay-verify="required" autocomplete="off" class="layui-input" disabled>
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.username.notice']*}
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.phone']*}
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="phone" value="{*user.phone*}" lay-verify="required|phone" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="email" class="layui-form-label">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.email']*}
              </label>
              <div class="layui-input-inline">
                  <input type="text" name="email" value="{*user.email*}" lay-verify="required|email" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item layui-hide">
              <div class="layui-input-inline">
                  <input type="text" name="action" value="update_userinfo">
              </div>
          </div>
          <div class="layui-form-item layui-hide">
              <div class="layui-input-inline">
                  <input type="text" name="token" value="{*user.token*}">
              </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button id="profilesubmit" class="layui-btn" lay-filter="profilesubmit" lay-submit="">{*locale['dashboard.menu.user_manage.form.submit']*}</button>
          </div>
        </form>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">{*locale['dashboard.header.profile.update_password']*}</div>
        <div class="layui-card-body">
          <form class="layui-form">
            <div class="layui-form-item">
              <label for="cupassword" class="layui-form-label">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.cupassword']*}
              </label>
              <div class="layui-input-inline">
                  <input type="password" name="cupassword" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label for="password" class="layui-form-label">
                  <span class="x-red">*</span>{*locale['dashboard.header.profile.form.password']*}
              </label>
              <div class="layui-input-inline">
                  <input type="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item layui-hide">
              <div class="layui-input-inline">
                  <input type="text" name="action" value="update_password">
              </div>
            </div>
            <div class="layui-form-item layui-hide">
              <div class="layui-input-inline">
                  <input type="text" name="token" value="{*user.token*}">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label"></label>
              <button id="pwsubmit" class="layui-btn" lay-filter="pwsubmit" lay-submit="">{*locale['dashboard.menu.user_manage.form.submit']*}</button>
            </div>
          </form>
    </div>
  </div>
    <script>
    layui.use(['form', 'layer'], function() {
        var $ = layui.jquery;
        var form  = layui.form;
        var layer = layui.layer;
        // 更新用户密码
        form.on('submit(pwsubmit)', function(data) {
          $('#pwsubmit').hide();
          $.ajax({
            url: "{*api_url*}", type:"POST", headers:{token:"{*user.token*}"}, data: data.field,
            error: function (res) {
              return layer.msg("请求失败", {time:2000}, function () {
                $('#pwsubmit').show();
              });
            },
            success: function (res) {
              if (res.code != 0 ){
                return layer.msg(res.msg, {time:2000}, function () {
                  $('#pwsubmit').show();
                });
              };
              layer.msg(res.msg, {time:1000}, function () {
                xadmin.close();
                xadmin.father_reload();
              })
            },
          });
          return false;
        });
        // 更新用户信息
        form.on('submit(profilesubmit)', function(data) {
          $('#profilesubmit').hide();
            $.ajax({
              url: "{*api_url*}", type:"POST", headers:{token:"{*user.token*}"}, data: data.field,
              error: function (res) {
                return layer.msg("请求失败", {time:2000}, function () {
                  $('#profilesubmit').show();
                });
              },
              success: function (res) {
                if (res.code != 0 ){
                  return layer.msg(res.msg, {time:2000}, function () {
                    $('#profilesubmit').show();
                  });
                };
                layer.msg(res.msg, {time:1000}, function () {
                  xadmin.close();
                  xadmin.father_reload();
                })
              },
            });
          return false;
        });
      });
   </script>
</body>
</html>
